//
//  ViewConfigSetting.swift
//  EasyCoding
//
//  Created by Fanxx on 2019/6/3.
//  Copyright © 2019 Fanxx. All rights reserved.
//

import UIKit

public struct UCSetting<TargetType> {
    public let action:(TargetType) -> Void
    public init(action: @escaping (TargetType) -> Void) {
        self.action = action
    }
}
extension UCSetting {
    ///组合多个样式
    public static func group(_ settings:UCSetting<TargetType>...) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            settings.forEach({ $0.action(target) })
        })
    }
    ///自定义
    public static func customize(_ action:@escaping (TargetType) -> Void) -> UCSetting<TargetType> {
        return .init(action: action)
    }
}
extension UCSetting where TargetType: AnyObject {
    ///使用原始属性赋值
    public static func key<ValueType>(_ kp: WritableKeyPath<TargetType, ValueType>,_ value: ValueType) -> UCSetting<TargetType> {
        return .init { target in
            var t = target
            t[keyPath: kp] = value
        }
    }
}

public let UCCellDefaultIdentifier = "Default"
